package com.jianger.dao;

import com.jianger.pojo.Task;
import com.jianger.utils.JDBCUtils;
import org.apache.commons.dbutils.QueryRunner;
import org.apache.commons.dbutils.handlers.BeanHandler;

import java.sql.SQLException;

/**
 * @author jianger
 * @ date  2018/4/4-16:37
 * @project com.jianger.dao
 */
public class TaskDaoImpl implements TaskDao {
    /**
     * 根据id查找task
     *
     * @param task_id id
     * @return task
     */
    public Task findTaskById(long task_id) {
        QueryRunner qr = new QueryRunner(JDBCUtils.getDataSource());
        String sql = "select * from task where task_id=?";
        Object[] params = new Object[]{task_id};
        try {
            return qr.query(sql, new BeanHandler<Task>(Task.class), params);
        } catch (SQLException e) {
            e.printStackTrace();
            return null;
        }

    }
}
